﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using TecBaseObjects.Interfaces;
using TecExtensions;


namespace TecBaseObjects.Objects {

    public class TecNotizObj : IBaseObject, ICloneable {

        #region Members

        private bool isDirty = false;
        private DateTime anrufDateTime = new DateTime(1900, 1, 1);
        private DateTime anlageDatum = new DateTime(1900, 1, 1);
        private DateTime änderungDatum = new DateTime(1900, 1, 1);
        private string nameAnrufer = null;
        private string telefonNummer = null;
        private string betreff = null;
        private string notizStrasse;
        private string plz = null;
        private string ort = null;
        private string eMAil = null;
        private Extensions.TelType telfonType = Extensions.TelType.Nothing;
        private int tecUserID;
        private int notizID;
        private int notizOrgKey;
        private int status = (int)Extensions.TelStatus.Nothing;
        private List<TecNotizTargetUser> targetUser;
        private string tecUser = null;
        private string notiz = null;
        private string sex;

        #endregion

        #region Constructor

        public TecNotizObj() {
        }

        public TecNotizObj(DateTime AnrufZeit, int TecUserID)
            : this() {
            this.anrufDateTime = AnrufZeit;
            this.tecUserID = TecUserID;
        }

        #endregion

        #region Properties

        public DateTime ÄnderungDatum {
            get { return this.änderungDatum; }
            set {
                if (this.änderungDatum != value) {
                    if (this.änderungDatum != new DateTime(1900, 1, 1)) {
                        this.IsDirty = true;
                    }
                    this.änderungDatum = value;
                }
            }
        }

        public DateTime AnlageDatum {
            get { return this.anlageDatum; }
            set { this.anlageDatum = value; }
        }

        public DateTime AnrufZeit {
            get { return this.anrufDateTime; }
            set { this.anrufDateTime = value; }
        }

        public Extensions.TelType AnrufType {
            get { return this.telfonType; }
            set {
                if (this.telfonType != Extensions.TelType.Nothing) {
                    this.IsDirty = true;
                }
                this.telfonType = value;
            }
        }

        public string Betreff {
            get { return this.betreff; }
            set {
                if (this.betreff != null) {
                    this.IsDirty = true;
                }
                this.betreff = value;
            }
        }

        public string ForTpUser {
            get {
                string ret = "";
                string kl = ", ";
                foreach (TecNotizTargetUser u in this.targetUser) {
                    ret +=  (ret == "" ? "" : kl) + u.LoginName.Trim();
                }
                return ret;
            }
        }

        public bool IsDirty {
            get { return this.isDirty; }
            set { this.isDirty = value; }
        }

        public bool IsMan {
            get { return this.sex == Extensions.TpSex.Man.GetStringValue(); }
        }

        public bool IsWoman {
            get { return this.sex == Extensions.TpSex.Woman.GetStringValue(); }
        }

        public string NotizEMail {
            get { return this.eMAil; }
            set {
                if (this.eMAil != null) {
                    this.IsDirty = true;
                }
                this.eMAil = value;
            }
        }

        public string NameAnrufer {
            get { return this.nameAnrufer; }
            set {
                if (this.nameAnrufer != null) {
                    this.IsDirty = true;
                }
                this.nameAnrufer = value;
            }
        }

        public string Notiz {
            get { return this.notiz; }
            set {
                if (this.notiz != null) {
                    this.IsDirty = true;
                }
                this.notiz = value;
            }
        }

        public int NotizID {
            get { return this.notizID; }
            set { this.notizID = value; }
        }

        public int NotizOrgKey {
            get { return this.notizOrgKey; }
            set { this.notizOrgKey = value; }
        }

        public string NotizStrasse {
            get { return this.notizStrasse; }
            set {
                if (this.notizStrasse != null) {
                    this.IsDirty = true;
                }
                this.notizStrasse = value;
            }
        }

        public string NotizPlz {
            get { return this.plz; }
            set {
                if (this.plz != null) {
                    this.IsDirty = true;
                }
                this.plz = value;
            }
        }

        public string NotizOrt {
            get { return this.ort; }
            set {
                if (this.ort != null) {
                    this.IsDirty = true;
                }
                this.ort = value;
            }
        }

        public string Sex {
            get { return this.sex; }
            set { this.sex = value; }
        }

        public int Status {
            get { return this.status; }
            set {
                if (this.status != (int)Extensions.TelStatus.Nothing) {
                    this.IsDirty = true;
                }
                this.status = value;
            }
        }

        public string StatusText {
            get {
                Extensions.TelStatus st = (Extensions.TelStatus)this.Status;
                return st.GetStringValue();
            }
        }

        public string TecUser {
            get { return this.tecUser; }
            set { this.tecUser = value; }
        }

        public int TecUserID {
            get { return this.tecUserID; }
            set { this.tecUserID = value; }
        }

        public string TelefonNummer {
            get { return this.telefonNummer; }
            set {
                if (this.telefonNummer != null) {
                    this.IsDirty = true;
                }
                this.telefonNummer = value;
            }
        }

        public List<TecNotizTargetUser> ZugeordneteUser {
            get { return this.targetUser; }
            set { this.targetUser = value; }
        }

        #endregion

        #region Methods

        public void AddTargetUser(TecNotizTargetUser user) {
            if (targetUser == null) {
                targetUser = new List<TecNotizTargetUser>();
            }
            targetUser.Add(user);
        }

        public void ClearTargetUser() {
            if (targetUser != null) {
                targetUser.Clear();
            }
        }

        public object Clone() {
            return this.MemberwiseClone();
        }



        #endregion

    }
}
